<?php
/**
 * TomatoCMS
 *
 * LICENSE
 *
 * This source file is subject to the GNU GENERAL PUBLIC LICENSE Version 2
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.gnu.org/licenses/gpl-2.0.txt
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@tomatocms.com so we can send you a copy immediately.
 *
 * @copyright    Copyright (c) 2009-2010 TIG Corporation (http://www.tig.vn)
 * @license        http://www.gnu.org/licenses/gpl-2.0.txt GNU GENERAL PUBLIC LICENSE Version 2
 * @version     $Id: list.phtml 3032 2010-05-25 08:00:42Z huuphuoc $
 */
?>
<?php
$this->headTitle($this->translator('assignment_list_page_title'));

$this->headLink()
    ->appendStylesheet($this->APP_STATIC_SERVER.'/js/jquery.ui/themes/base/ui.core.css')
    ->appendStylesheet($this->APP_STATIC_SERVER.'/js/jquery.ui/themes/base/ui.resizable.css')
    ->appendStylesheet($this->APP_STATIC_SERVER.'/js/jquery.ui/themes/base/ui.dialog.css')
    ->appendStylesheet($this->APP_STATIC_SERVER.'/js/jquery.ui/themes/base/ui.theme.css')
    ->appendStylesheet($this->APP_STATIC_SERVER . '/js/jquery.ui/themes/base/ui.datepicker.css')
    ;

$this->headScript()
    ->appendFile($this->APP_STATIC_SERVER.'/js/jquery.ui/ui.core.js')
    ->appendFile($this->APP_STATIC_SERVER.'/js/jquery.ui/ui.draggable.js')
    ->appendFile($this->APP_STATIC_SERVER.'/js/jquery.ui/ui.droppable.js')
    ->appendFile($this->APP_STATIC_SERVER.'/js/jquery.ui/ui.resizable.js')
    ->appendFile($this->APP_STATIC_SERVER.'/js/jquery.ui/ui.dialog.js')
    ->appendFile($this->APP_STATIC_SERVER . '/js/jquery.ui/ui.datepicker.js')
    ;
?>

<div class="grid_12 t_a_ui_breadcrumb">
    <span><a href="<?php echo $this->url(array(), 'order_order_list'); ?>"><?php echo $this->translator('order_list_breadcump'); ?></a></span>
    <span><a href="<?php echo $this->url(array('order_id' => $this->order_id), 'order_order_view'); ?>"><?php echo $this->translator('order_view_breadcump'); ?></a></span>
    <span><?php echo $this->translator('assignment_assign_job');?></span>
</div>

<?php if(!$this->isAllowed):?>
    <div class="grid_12 t_a_bottom"><?php echo $this->translator('assignment_assign_job_guide');?></div>
<?php else:?>

<!-- Prodcut without assigned-->
<div class="grid_12 t_a_bottom">
    <div class="grid_8 t_a_ui_helper_line">
        <h3><?php echo $this->translator('assignment_assign_guide');?></h3>
    </div>
</div>
<div class="grid_12"><?php echo $this->flashMessenger(); ?></div>
<?php if(count($this->products)<=0):?>
<div class="grid_12 t_a_bottom"><?php echo $this->translator('aissgnment_list_not_found') ?></div>
<?php else:?>
<form action="" method="POST" id="assignJobForm">
<div class="grid_12 t_a_ui_data_list_header">
    <div class="grid_4 alpha">
        <div><input type="checkbox" id="checkAll" /><?php echo $this->translator('order_product_name'); ?></div>
    </div>
    <div class="grid_4"><?php echo $this->translator('order_values'); ?></div>
    <div class="grid_2"><?php echo $this->translator('order_quantity'); ?></div>
    <div class="grid_2 omega"><?php echo $this->translator('order_amount'); ?></div>
</div>
<div class="grid_12 t_a_bottom" id="ordersDetail">
    <?php foreach ($this->products as $row):?>
    <?php
        /**
        * Attribute and value info
        **/
        $attValue = isset($this->arrAllAtVal[$row->order_detail_id])?$this->arrAllAtVal[$row->order_detail_id]:null;
    ?>
    <input type="hidden" value="<?php echo $row->order_invoice;?>" name="order_invoice_<?php echo $row->order_detail_id;?>"/>
    <input type="hidden" value="<?php echo $row->production_duration;?>" name="production_duration_<?php echo $row->order_detail_id;?>"/>
    <div id="tOrderRow_<?php echo $row->order_id; ?>" class="clearfix t_a_ui_data_list_content">
        <div class="grid_4 alpha">
            <div><input type="checkbox" name="ckb_order_id[]" class="selectODId" value="<?php echo $row->order_detail_id; ?>" />
            <?php echo $row->product_admin_name?></div>
        </div>
        <div class="grid_4">
        	<?php if($attValue):?>
            	<?php foreach($attValue as $a_t):?>
                <div><b><?php echo $a_t[0];?>:</b> <?php echo $a_t[1];?></div>
            	<?php endforeach;?>
            <?php else:?>
            	-
            <?php endif;?>
        </div>
        <div class="grid_2"><?php echo $row->order_detail_quantity;?></div>
        <div class="grid_2 omega"><?php echo $row->order_detail_quantity*$row->order_detail_product_price;?> <?php echo $row->order_detail_currency;?></div>
    </div>
    <?php endforeach;?>
</div>
<?php if(isset($this->userAccount->enterprise_id) && $this->assAllow):?>
<div class="grid_12 t_a_bottom">
    <div class="grid_6 alpha">&nbsp;</div>
    <div class="grid_6 omega">
        <div class="t_a_right">
            <?php echo $this->translator('assignment_producer'); ?>:
            <select style="width:170px" name="producer_account_id">
                <option value="">--<?php echo $this->translator('assignment_please_choose')?>--</option>
                <?php foreach($this->arrSProducer as $r_pro):?>
                <option value="<?php echo $r_pro->user_id;?>"><?php echo trim($r_pro->full_name)?$r_pro->full_name:$r_pro->user_name?></option>
                <?php endforeach;?>
            </select>
            <button type="submit"><span><?php echo $this->translator('assignment_assign_button'); ?></span></button>
        </div>
    </div>
</div>
<?php endif;?>
</form>
<?php endif;?>

<!-- Assignment list of assigned -->
<div class="grid_12 t_a_bottom">
    <div class="grid_8 t_a_ui_helper_line">
        <h3><?php echo $this->translator('assignment_assigned_guide');?></h3>
    </div>
</div>
<?php if (count($this->assignments) <= 0) : ?>
<div class="grid_12 t_a_bottom">
    <?php echo $this->translator('aissgnment_list_not_found'); ?>
</div>
<?php else : ?>
<div class="grid_12 t_a_ui_data_list_header" style="height:40px; line-height:20px;">
    <div class="grid_2 alpha" style="width:100px;"><?php echo $this->translator('assignment_order_id'); ?></div>
    <div class="grid_2"><?php echo $this->translator('assignment_product_name'); ?></div>
    <div class="grid_2"><?php echo $this->translator('assignment_producer'); ?></div>
    <div class="grid_1"><?php echo $this->translator('assignment_status'); ?></div>
    <div class="grid_2" style="width:100px;"><?php echo $this->translator('assignment_create_date'); ?></div>
    <div class="grid_2"><?php echo $this->translator('assignment_due_date'); ?></div>
    <div class="grid_2 omega"><?php echo $this->translator('assignment_finish_date'); ?></div>
</div>

<div class="grid_12 t_a_bottom" id="articles">
    <?php foreach ($this->assignments as $row) : ?>
    <?php

        /**
        * Handle php code at here
        * ---Get product info
        * ---Get producer info
        * ---Get assigner info
        **/
        $product  = isset($this->arrProduct[$row->assignment_id])?$this->arrProduct[$row->assignment_id]:null;
        $producer = isset($this->arrProducer[$row->assignment_id])?$this->arrProducer[$row->assignment_id]:null;
        $assigner = isset($this->arrAssigner[$row->assignment_id])?$this->arrAssigner[$row->assignment_id]:null;

        $p_name = 'null';
        if($producer){
            $p_name = (trim($producer->full_name))?$producer->full_name:$producer->user_name;
        }

        $as_name = 'null';
        if($assigner){
            $as_name = (trim($assigner->full_name))?$assigner->full_name:$assigner->user_name;
        }
    ?>
    <div id="assignmetnRow_<?php echo $row->assignment_id; ?>" class="clearfix t_a_ui_data_list_content">
        <div class="grid_2 alpha"  style="width:100px;">
            <div>
                <?php echo $row->order_id;?>
            </div>

            <div class="t_a_top t_a_ui_helper_action">
                <?php if ($this->allow('view')) : ?>
                <a href="<?php echo $this->url(array('assignment_id' => $row->assignment_id), 'assignment_assignment_view'); ?>"><?php echo $this->translator('assignment_list_action_view'); ?></a>
                <?php endif; ?>
            </div>
        </div>
        <div class="grid_2"><?php echo ($product)?$product->product_admin_name:null;?></div>
        <div class="grid_2">
            <?php echo $p_name.' (<b>by</b> '.$as_name.')';?>
        </div>
        <div class="grid_1"><?php echo isset($this->arrStatus[$row->assignment_id])?$this->translator('assignment_status_'.$this->arrStatus[$row->assignment_id]):'&nbsp';?></div>
        <div class="grid_2" style="width:100px;"><?php echo $row->assignment_create_date?date('d-m-Y',strtotime($row->assignment_create_date)):'-'; ?></div>
        <div class="grid_2"><?php echo $row->assignment_create_date?date('d-m-Y', strtotime($row->assignment_create_date)):'-'; ?></div>
        <div class="grid_2 omega"><?php echo $row->assignment_finish_date?date('d-m-Y',strtotime($row->assignment_finish_date)):'-'; ?></div>
    </div>
    <?php endforeach; ?>
</div>
<?php endif; ?>
<?php endif; ?>

<div id="messageDialog"></div>
<div id="confirmDialog"></div>

<script type="text/javascript">
$(document).ready(function() {
    /**
    * Select/Deselect all rows handler
    */
    $('#checkAll').click(function() {
        $('input[type="checkbox"].selectODId').attr('checked', $(this).attr('checked'));
    });
});
</script>